/**
 * @file adpt_alarm.h
 * @synopsis  
 * @author wen wjcapple@163.com
 * @version 2.0
 * @date 2016-12-29
 */
#ifndef __ADPT_ALARM_H__
#define __ADPT_ALARM_H__
#include"global.h"
#include"otdr_ch.h"
#ifdef __cplusplus
extern  "C"{
#endif
//切换通道
#define SWITCH_CH	0
//发送告警并切换通道
#define SEND_ALARM_AND_SWITCH_CH 1
//继续测量本通道
#define CONTINUE_TEST		2
//将光线段配置参数转换成告警模块所需要的
int32_t convert_stdcfg_host2alarmodule(
		struct _tagFiberSecCfg *pfiber_cfg, 
		struct _tagAlarmModuleAdpt *pAlarmAdpt);
//将光线段配置参数中的标准曲线转换成告警模块所需要的
int32_t convert_stddata_host2alarmmodule(
		int16_t std_data_buf[], 
		float data_buf[], 
		int32_t num);
//将光线段配置中的事件的参数转换成告警模块所需要的
int32_t convert_stdevent_host2alarmmodule(
		struct _tagOtdrEvent *pstd_event, 
		OTDREvent_t event_buf[], 
		int32_t num);
//将光纤段配置中光线段转换成告警模块所需的参数
int32_t convert_stdfiber_host2alarmmodule(
		struct _tagFiberSecCfg *pfiber_cfg, 
		FiberSegment_t *fiber_val_module,
		int32_t num);
		
//分配告警模块接口以及管理告警所需的缓冲区
int32_t malloc_alarmmodule_resource(int32_t fiber_sec_num, struct _tagAlarmModuleAdpt *pAlarmAdpt);
//分配告警模块接口以及管理告警所需的缓冲区
int32_t free_alarmmodule_resource(struct _tagAlarmModuleAdpt *pAlarmAdpt);
//初始化告警模块
int32_t intial_alarmmodule_adpt(struct _tagAlarmModuleAdpt *pAlarmAdpt);

//将算法模块所得事件，光线段转换成告警模块所需要的格式
int32_t convert_event_algor2alarmmodule(
	       	const EventPoint_t ep_algo_buf[],
		OTDRTestResult_t  *tr_alarm,
		int32_t ep_num);
int32_t convert_efs_algor2alarmmodule(
		const FiberSection_t efs_algo_buf[],
		OTDRTestResult_t  *tr_alarm,
		int32_t efs_num);
int32_t convert_para_algor2alarmmodule(
		const OtdrTestParam_t *algo_para,
		OTDRTestPara_t *alarm_para);
int32_t convert_tr_algor2alarmmodule(
		const OtdrTestResult_t *palgor_tr,
		OTDRTestResult_t *palarm_tr);
//将曲线从算法模块转换成告警模块所需要的
int32_t convert_curv_aglo2alarmmoudle(OtdrTestResult_t *palgor_curv,OTDRCurveInfo_t *palarm_curv); 
//更新告警cache
int32_t refresh_alarm_cache(
		struct _tagCHAlarmCache *pAlarmCache,
		FiberAlarmInfo_t *pCurAlarm,
		struct _tagSecFiberAlarm *pHostAlarm);
//将当前告警模块格式转换成协议格式
int32_t convert_alarm_moudule2host( 
		FiberAlarm_t *pmodule_alarm, 
		struct _tagAlarm *phost_alarm,
		int32_t ch);
//初始化告警缓存
int32_t initial_alarm_cache(
		struct _tagCHAlarmCache *pAlarmCache,
		int32_t sec_num);
//比较两个告警是否相同
int32_t compare_alarm(
		FiberAlarm_t *palarm_cache, 
		FiberAlarm_t *palarm_cur);
//更新统计数据
int32_t refresh_fiber_statistc(
		const OtdrTestResult_t *tr,
		struct _tagCHFiberSec *pfiber_sec,
		int32_t ch);
//将光线段配置格式从host转换成告警模块格式
int32_t convert_tr_host2alarmmodule(
		const struct _tagHostTestResult *phost_tr,
		OTDRTestResult_t *palarm_tr);
//将配置参数从光线段配置转换到告警模块的格式
int32_t convert_testpara_host2alarmmodule(
		struct _tagHostOtdrPara  *phost_para,
		OTDRTestPara_t *palarm_para);
int32_t compare_alarm_v1(
		FiberAlarm_t *palarm_cache, 
		struct _tagAlarm *palarm_cur);
int32_t get_max_serious_alarm(FiberAlarmInfo_t *pCurAlarm );
#ifdef __cplusplus
extern  "C"{
#endif
#endif
